const express = require('express');
const app = express();
const router = express.Router();
const authServices = require("./../services/auth");
const { sendResult } = require('../handler');

router.get("/resource/view", authServices.queryAuthTree, (req, res) => {
    res.render("admin/pages/authTree");
});

router.get("/resource/tree", authServices.queryAuthTree, (req, res) => {
    res.send(res.locals.data.authTree);
});

router.post("/resource/create", authServices.resourceAdd, (req, res) => {
    res.redirect("/admin/auth/resource/view");
});

router.get("/resource/destory", authServices.destoryResource, (req, res) => {
    res.redirect("/admin/auth/resource/view");
});

router.get("/role/view", authServices.roleRecord, (req, res) => {
    res.render("admin/pages/roleRecord");
})

router.get("/role/record", authServices.roleRecord, (req, res) => {
    sendResult(res, res.locals.data.roleRecord);
})

router.post("/role/create", authServices.roleAdd, (req, res) => {
    sendResult(res, true);
});

router.post("/role/member/create", authServices.roleAdd, (req, res) => {
    sendResult(res, true);
});

router.get("/member/view", authServices.userRecord, (req, res) => {
    res.render("admin/pages/userRecord");
});

module.exports = router;